package com.tuozixuan.shell.command;

import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;

@ShellComponent
public class AvailabilityDemo2 {
	private boolean connected = false;

	@ShellMethod("Connect server")
	public void connect2() {
	    connected = true;
	}

	@ShellMethod("Download")
	public void download2() {
	    System.out.println("Downloaded.");
	}

	@ShellMethod("Upload")
	public void upload2() {
	    System.out.println("Uploaded.");
	}


	// 直接在提供命令动态可用性的方法上通过注解`@ShellMethodAvailability`指定命令方法名
	@ShellMethodAvailability({"download2", "upload2"})
	public Availability connectCheck() {
	    return connected ? Availability.available():Availability.unavailable("you are not connected");
	}
}
